package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.PurchaseList;
import com.atguigu.jxc.service.PurchaseListGoodsService;
import com.atguigu.jxc.service.PurchaseListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author 杨林
 * @create 2023-01-29 20:42 星期日
 * description:
 */
@RestController
@RequestMapping("/purchaseListGoods")
public class PurchaseListGoodsController {

    @Autowired
    PurchaseListGoodsService purchaseListGoodsService;

    @Autowired
    PurchaseListService purchaseListService;

    /**
     * 进货单保存
     * @return
     */
    @PostMapping("/save")
    public ServiceVO save(PurchaseList purchaseList, String purchaseListGoodsStr){

        return purchaseListGoodsService.save(purchaseList,purchaseListGoodsStr);
    }

    /**
     * 进货单列表展示（可条件查询：单据号模糊、供应商、是否付款和日期区间）
     * @return
     */
    @PostMapping("/list")
    public Map<String,Object> list(String purchaseNumber,
                                   Integer supplierId,
                                   Integer state,
                                   String sTime,
                                   String eTime){
        return purchaseListGoodsService.list(purchaseNumber,supplierId,state,sTime,eTime);
    }

    /**
     * 进货单商品信息展示
     * @return
     */
    @PostMapping("/goodsList")
    public Map<String,Object> goodsList(Integer purchaseListId){

        return purchaseListGoodsService.goodsList(purchaseListId);
    }

    /**
     * 进货单删除
     * @param purchaseListId
     * @return
     */
    @PostMapping("/delete")
    public ServiceVO delete(Integer purchaseListId){

        return purchaseListService.delete(purchaseListId);
    }


    /**
     * 支付结算（修改进货单付款状态）
     * @param purchaseListId
     * @return
     */
    @PostMapping("/updateState")
    public ServiceVO updateState(Integer purchaseListId){

        return purchaseListService.updateState(purchaseListId);
    }


    /**
     * 进货统计（可根据 商品类别、商品编码或名称 条件查询）
     * @param sTime
     * @param eTime
     * @param goodsTypeId
     * @param codeOrName
     * @return
     */
    @PostMapping("/count")
    public String count(String sTime,
                        String eTime ,
                        Integer goodsTypeId,
                        String codeOrName){

        return purchaseListService.count(sTime,eTime,goodsTypeId,codeOrName);
    }

}
